<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<link href="${path}/include/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<jsp:include page="/WEB-INF/pages/qtop.jsp" flush="true"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>在线问答系统</title>
</head>
<body>
 	<script src="${path}/include/bootstrap/js/jquery.min.js"></script>
   	<script src="${path}/include/bootstrap/js/bootstrap.min.js"></script>
	
	<form class="form-horizontal" role="form" method="post" >
	<div style="padding: 0px 100px 0px">
		<h3><B>提问题</B><h3>
  	</div>
    <div class="form-group" style="padding: 0px 100px 0px">
      <div class="col-sm-10">
         <input type="text" class="form-control" id="qtitle" name="qtitle"
            placeholder="标题：一句话说清楚问题，用句号结尾">
      </div>
      <!--富文本插件-->
      
       <div class="form-group" style="padding: 50px 225px 10px 30px">
  			<textarea class="form-control" rows="8" id="qbody" name="qbody"></textarea>
	   </div>
    </div>
    
   	<div class="pull-right" style="padding: 0px 300px 0px">
      <div class="col-sm-offset-2 col-sm-10">
         <button type="button" onclick="tQuestion();" class="btn btn-default btn-lg">发布问题</button>
      </div>
   </div>
    </form>
    
   <script type="text/javascript">
   		function tQuestion(){
   			$.ajax({
   				cache : true,
   				type : "POST",
   				url : "<c:url value='/ques/ask'/>",
   				data :{"qtitle":$('#qtitle').val(),"qbody":$('#qbody').val()},
   				error : function(
   						request){
   					return;
   				},
   				success : function(data){
   					if(data=="0"){
   						window.location.href="<c:url value='/ques/index' />";
   					}else if(data=="2"){
   						alert("标题不能为空");
   					}else if(data=="3"){
   						alert("内容不能为空");
   					}else if(data=="4"){
   						alert("标题和内容不能为空");
   					}
   				}
   			});
   		}
   </script>
    
</body>
</html>